#!/usr/bin/env node

// setTimeout(function() {
//     console.log('first');
// },1000);
// console.log('second');

// 01-bomb.js

class TimerBomb {
    constructor() {
        this.timer = null;
    }

    start() {
        console.log('炸弹启动，3秒后爆炸...');
        this.timer = setTimeout(() => {
            console.log('炸弹爆炸!');
        }, 3000);
    }

    clear() {
        if (this.timer) {
            clearTimeout(this.timer);
            console.log('炸弹定时器已取消，安全！');
            this.timer = null;
        } else {
            console.log('炸弹定时器未启动，无需取消。');
        }
    }
}

// 实例化两个定时炸弹对象
const b1 = new TimerBomb();
const b2 = new TimerBomb();

b1.start();
b2.start();

setTimeout(() => {
    b2.clear();
}, 1000);
